<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新建</title>
    <script src="../../js/header.js"></script>
    <style type="text/css">
        html, body, #add {
            padding: 0px;
            margin: 0px;
        }
        #add{
            border-top: 3px solid #0D9AFF;
            padding: 25px;
        }
        .tab-title{
            font-size: 16px;
            font-weight: bold;
            border-left: 4px solid #0D9AFF;
            font-family: PingFangSC-Medium;
            padding-left:10px;
            margin-bottom: 20px;
        }
        .el-dialog__footer {
            padding: 10px 20px 20px;
            text-align: center;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
        }
        .el-dialog__body {
            color: rgb(96, 98, 102);
            font-size: 14px;
            word-break: break-all;
            padding: 0px 20px;
        }
        #excel {
            display: none;
        }
        .el-input__inner {
            -webkit-appearance: none;
            background-color: #FFF;
            background-image: none;
            border-radius: 4px;
            border: 1px solid #DCDFE6;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            color: #606266;
            display: inline-block;
            font-size: inherit;
            height: 30px;
            line-height: 30px;
            outline: 0;
            padding: 0 15px;
            -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
            transition: border-color .2s cubic-bezier(.645,.045,.355,1);
        }
        .el-select,.el-input-number.el-select ,.el-date-editor.el-input, .el-date-editor.el-input__inner {
			width: 100%;
		}
        .listed .el-form-item__label{
            letter-spacing: 3px;
        }
        .el-textarea {
            width: 100%;
        }

        /* 搜索按钮样式修改 */
        #add .el-button.is-circle.search_btn{
            position: absolute;
            right: 0;
            top: 0;
            border: 0;
            background: none;
        }
        #add .el-button.is-circle.search_btn i{
            font-size: 17px;
        }

        .companycredit_gonggao .el-form-item__content{
            margin-left: 0!important;
        }
        #add .companycredit_publicstate .el-select{
            width: auto;
        }

        /* 拟制公告---封装样式 */
        .content_tab{
            padding: 20px 0;
        }
        .border_btm{
            border-bottom: 1px solid #ddd;
        }
        .border_left{
            border-left: 1px solid #ddd;
        }
    </style>
</head>
<body>
<div v-cloak id="add">
    <div style="margin-top: 10px;">
        <el-form :model="addForm" :rules="rules" ref="addForm" label-width="150px">
            <el-row>
                <el-col span="9">
                    <el-form-item label="创建人:" prop="createUser" label-width="130px">
                        <el-input v-model="addForm.createUser " placeholder="" disabled></el-input>
                    </el-form-item>
                </el-col>
                <el-col span="9">
                    <el-form-item label="创建人单位:" prop="createUserUnit" label-width="190px">
                        <el-input v-model="addForm.createUserUnit" placeholder="" disabled></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="9">
                    <el-form-item label="创建时间:" prop="createTime" label-width="130px">
                        <el-date-picker
                                v-model="addForm.createTime"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="创建时间"
                                disabled>
                        </el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="14">
                    <el-form-item label="公布类别:" prop="isPublic" label-width="120px">
                        <el-radio-group v-model="addForm.isPublic" :disabled="addFormDisabled">
                            <el-radio :label="0">公示通报</el-radio>
                            <el-radio :label="1">标准规范</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="14">
                    <el-form-item label="公开地址类型:" prop="publicType" label-width="120px">
                        <el-radio-group v-model="addForm.publicType" :disabled="addFormDisabled">
                            <el-radio :label="0">服务门户</el-radio>
                            <el-radio :label="1">工作门户</el-radio>
                            <el-radio :label="2">服务门户和工作门户</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col span="22">
                    <el-form-item label="标题:" prop="title" label-width="120px">
                        <el-input v-model.trim="addForm.title" maxlength="500" placeholder="" :disabled="addFormDisabled"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label="内容:" prop="publicityContent" label-width="120px">
                            <el-input
                                    maxlength="5000"
                                    type="textarea"
                                    :autosize="{ minRows: 8, maxRows: 8}"
                                    placeholder="请输入内容"
                                    v-model="addForm.publicityContent"
                                    :disabled="addFormDisabled">
                            </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label="附件:" prop="" label-width="120px">
                        <iframe width="100%"  style="height: 200px;border: none;"   :src="link"></iframe>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <div style="float: right;">
                        <el-button type="primary" size="small" style="width: 60px;height: 30px;" @click="zabcub()">暂存</el-button>
                        <el-button type="success" size="small" style="width: 60px;height: 30px;" @click="public()">发布</el-button>
                    </div>
                </el-col>
            </el-row>
        </el-form>
    </div>
</div>
<script>
    var vm = new Vue({
        el: '#add',
        data(){
            return{
                uuid:'',
                link:'',//iframe链接
                userInfo:'',
                addForm: {
                    id:'',
                    createUser:'',
                    createUserUnit:'',
                    createTime:'',
                    title:'',
                    publicityContent:'',
                    publicType:'',
                    isPublic:''
                },
                addFormDisabled:false,
                rules: {
                    createUser: [{
                        required: true,
                        message: "创建人必填",
                        trigger: "blur"
                    }],
                    createUserUnit: [{
                        required: true,
                        message: "创建人单位必填",
                        trigger: "blur"
                    }],
                    createTime: [{
                        required: true,
                        message: "创建时间必填",
                        trigger: "blur"
                    }],
                    title: [{
                        required: true,
                        message: "标题必填",
                        trigger: "blur"
                    },{
                        max : 500,
                        message : '长度最大为500个字符',
                        trigger : 'blur'
                    }],
                    publicityContent: [{
                        required: true,
                        message: "内容必填",
                        trigger: "blur"
                    },{
                        max : 5000,
                        message : '长度最大为5000个字符',
                        trigger : 'blur'
                    }],
                    publicType: [{
                        required: true,
                        message: "公开地址类型必填",
                        trigger: "blur"
                    }],
                    isPublic: [{
                        required: true,
                        message: "公布类别必填",
                        trigger: 'blur'
                    }]
                }
            }
        },
        created: function() {
            this.userInfo = JSON.parse(localStorage.getItem('userInfo'));
        },
        mounted(){
            this.getUuid();
        },
        methods: {
            //获取UUID的方法
            getUuid() {
                this.addForm.createUser=this.userInfo.loginName;
                this.addForm.createUserUnit=this.userInfo.orgName;
                let date = new Date();
                let y = date.getFullYear();
                let MM = date.getMonth() + 1;
                MM = MM < 10 ? ('0' + MM) : MM;
                let d = date.getDate();
                d = d < 10 ? ('0' + d) : d;
                let h = date.getHours();
                h = h < 10 ? ('0' + h) : h;
                let m = date.getMinutes();
                m = m < 10 ? ('0' + m) : m;
                let s = date.getSeconds();
                s = s < 10 ? ('0' + s) : s;
               	console.log(y + '-' + MM + '-' + d);
               	this.addForm.createTime = y + '-' + MM + '-' + d;
                axios({
                    method: 'get',
                    url: '/dzjwgr/uuid/getUuid',
                })
                    .then(response => {
                        if (response.data.code == 200) {
                            this.uuid = response.data.data;
                            this.link="../upload/annex.html?uuid="+this.uuid+"&flag=1";
                        } else {
                            this.$message.error(response.data.msg);
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            },
            /* 列表页清空 */
            clearForm() {
                this.$refs.addForm.resetFields();
                this.uuid = '';
                this.addForm.title = '';
                this.addForm.publicityContent = '';
                this.addForm.publicType = '';
                this.addForm.isPublic = '';
            },

            //暂存
            zabcub(){
                this.$refs.addForm.validate(valid => {
                    if (valid) {
                        this.addForm.id=this.uuid;
                        axios({
                            method: 'post',
                            url: '/dzjwgr/publicity/saveOnly',
                            data: this.addForm
                        })
                            .then(response => {
                                let data = response.data;
                                if (data.code == 200) {
                                    this.$message({
                                        message: '暂存成功',
                                        type: 'success'
                                    });
                                    this.getUuid();
                                    this.clearForm(); // 重置
                                    this.getUuid();
                                } else {
                                    this.$message.error(data.msg);
                                }
                            })
                            .catch(function (error) {
                                console.log(error);
                            })
                    }else {
                            console.log("error!!");
                            return false;
                        }
                    });
            },
            //公布
            public(){
                this.$refs.addForm.validate(valid => {
                    if (valid) {
                        this.addForm.id=this.uuid;
                        axios({
                            method: 'post',
                            url: '/dzjwgr/publicity/save',
                            data: this.addForm
                        })
                            .then(response => {
                                let data = response.data;
                                if (data.code == 200) {
                                    this.$message({
                                        message: '发布成功',
                                        type: 'success'
                                    });
                                    this.getUuid();
                                    this.clearForm(); // 重置
                                    this.getUuid();
                                } else {
                                    this.$message.error(data.msg);
                                }
                            })
                            .catch(function (error) {
                                console.log(error);
                            })
                    }else {
                            console.log("error!!");
                            return false;
                        }
                    });
            }
        }
    })
</script>
</body>
</html>